package com.atguigu.cloud.controller;/**
 * @Auter zzh
 * @Date 2024/11/13
 */

import com.atguigu.cloud.entities.Shopcar;
import com.atguigu.cloud.sevice.Impl.ShopcarServiceImpl;
import com.atguigu.cloud.tool.resp.ResultData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: keshe
 * @package: com.atguigu.cloud.controller
 * @className: shopcarcontrollor
 * @author: Eric
 * @description: TODO
 * @date: 2024/11/13 18:33
 * @version: 1.0
 */
@Tag(name = "购物车表", description = "购物车表增删改")
@RestController
public class Shopcarcontrollor {
    @Resource
    ShopcarServiceImpl shopcarService;

    //增加购物车
    @PostMapping(value = "/shopcar/add")
    @Operation(summary = "添加购物车", description = "添加购物车")
    public ResultData<String> addshopcar(@RequestBody Shopcar shopcar){
        System.out.println(shopcar.toString());
        int i = shopcarService.add(shopcar);
        return ResultData.success("成功插入记录，返回值："+i);
    }

    //删除购物车
    @DeleteMapping(value = "/shopcar/del/{id}")
    @Operation(summary = "删除购物车", description = "删除购物车")
    public ResultData<Integer> deleteshopcar(@PathVariable("id") Integer id) {
        Integer i=shopcarService.delete(id);
        return ResultData.success(i);
    }

    //修改购物车
    @PutMapping(value = "/shopcar/update")
    @Operation(summary = "修改购物车", description = "修改购物车")
    public ResultData<String> updateshopcar(@RequestBody Shopcar shopcar){
        int i = shopcarService.update(shopcar);
        return ResultData.success("成功修改记录，返回值："+i);
    }

    //查询购物车
    @GetMapping(value = "/shopcar/get/{id}")
    @Operation(summary = "查询购物车", description = "查询购物车")
    public ResultData<Shopcar> getById(@PathVariable("id") Integer id){
        Shopcar shopcar = shopcarService.getById(id);
        return ResultData.success(shopcar);
    }

    //查询购物车列表
    @GetMapping(value = "/shopcar/getall")
    @Operation(summary = "查询所有购物车", description = "查询所有购物车")
    public ResultData<List<Shopcar>> getAll(){
        List<Shopcar> shopcars = shopcarService.getAll();
        return ResultData.success(shopcars);
    }
    //分页查询购物车
    @GetMapping(value = "/shopcar/paginationQuery/{page}/{size}/{userid}")
    @Operation(summary = "分页查询购物车", description = "传入当前页号和每页记录数和用户id")
    public ResultData<Page<Shopcar>> paginationQuery(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @PathVariable("userid") Integer userid){
        Page<Shopcar> shopcars = shopcarService.Pageuserfind(page,size,userid);
        return ResultData.success(shopcars);
    }

}
